package kr.hkit.powerjava.chapter22.submit;

import java.util.ArrayList;

public class DepartmentDAO implements DaoInterface<Department> {
	private ArrayList<Department> arList; 

	public DepartmentDAO(ArrayList<Department> arList) {
		this.arList = arList;
	}

	@Override
	public void addItem(Department item) { //추가
		arList.add(item);
	}

	@Override
	public Department searchItem(Department item) { //검색
		if (arList.contains(item)) { //equal오버라이딩해야
			return arList.get(arList.indexOf(item));
		} else {
			return null;
		}		
	}

	@Override
	public void updateItem(Department item) { // 수정
		arList.set(arList.indexOf(item), item); 
	}

	@Override
	public void delItem(Department item) { //삭제
		if (arList.contains(item)) {
			arList.remove(arList.indexOf(item)); //참조주소 삭제 
		}else {
			System.out.println("해당 학생 정보가 없습니다.");
		}	
	}

	@Override
	public void prnList() {
		prnHeader();			
		for(Department dept : arList) { //arList에서 한개씩 꺼내서 출력
			System.out.println(dept);
		}
	}

	@Override
	public void prnHeader() {
		String header = String.format("%3s\t%5s\t%3s","학과번호","학과명","위치");
		System.out.println(header);
	}

}
